<template>
	<view class="fui-page-group ">
		<view class="fui-page fui-page-current">
			<view class="fui-header fui-header-success">
				<view class="fui-header-left">
					<navigator 	 class="back external" @tap="go">
						<text class="iconfont icon-fanhui">商城</text>
					</navigator>
				</view>
				<view class="title">用户登录</view>
				<view class="fui-header-right"></view>
			</view>
			<view class="fui-content page-login">			
				<view class="panel-logo">
					<image :src="qiniu+'/images/16/2019/07/oewNTmf558zbQ798Q5ob5OOG3rF7c3.png'" mode="widthFix"></image>
				</view>
				<view class="panel-login">
					<view class="fui-cell-group fui-cell-group-o">
						<view class="fui-cell">
							<view class="fui-cell-info">
								<input type="text" placeholder="请输入用户名" class="fui-input" id="username" v-model="username">
							</view>
						</view>
						<view class="fui-cell">
							<view class="fui-cell-info">
								<input password type="text" placeholder="请输入密码" class="fui-input" id="password" v-model="password">
							</view>
						</view>
					</view>
					<view class="btn btn-success block btn-submit" data-type="" id="btn-submit" @click="ok">登录</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	var t = getApp().globalData,
		e = t.requirejs('core'),
		i = t.requirejs('foxui'),
		a = t.requirejs('jquery');
	export default {
		data() {
			return {
				username:'',
				password:'',
				qiniu:t.qiNiu
			}
		},
		onShow(){
			//如果已经登录，则跳转到首页
			let user_token=t.getCache('user_token','');
			if(user_token!=''){
				uni.switchTab({
				    url: '/pages/merchmanage/merchmanage'
				});
			}
		},
		methods: {
			shop(){
				e.get('merchmanage.shop', {}, function(data) {
					t.setCache('user_shop',data.result.shop);
				})
			},
			go(){
				let url=t.globalData.api
				url=t.globalData.api.replace("jxshops.php?m=z&do=mobile","jxshops.php")　
				location.href=url
			},
			ok(){
				let self=this
				if(this.username==''){
					return uni.showToast({
					    title: '请输入用户名',
						icon:"none",
					    duration: 2000
						
					});
				}
				if(this.password==''){
					return uni.showToast({
					    title: '请输入密码',
						icon:"none",
					    duration: 2000
					});
				}
				//登录数据
				e.post('merchmanage.login', {'username':this.username,'password':this.password}, function(data) {
					if(data.status==1){
						t.setCache('user_token',data.result.token);
						self.shop(data.result.token)
						//登录成功直接跳转到首页
						uni.navigateTo({
						    url: '/pages/merchmanage/merchmanage'
						});
						
					}else{
						uni.showToast({
						    title: '登录失败',
							icon:"none",
						    duration: 2000
						});
					}
				});
				
			}
		}
	}
</script>

<style>
.fui-header{
	box-shadow: 0 -4rpx 8rpx 0px #034c03;
}
.fui-header .iconfont {
	font-size: 28rpx;
	padding: 0 20rpx;
}
.fui-content{
	position: absolute;
	top: 88rpx;	
	right: 0;
	bottom:0;
	left: 0;
	background: #5cb85c;
}
.page-login .panel-logo {
    height: 160rpx;
    width: 160rpx;
    padding: 4rpx;
    background: #fff;
    border-radius: 50%;
	overflow: hidden;
	margin: 150rpx auto 0;
}
.page-login .panel-logo image {
    width: 157rpx;
    border-radius: 50%;
}
.page-login .panel-login {
    height: auto;
    overflow: hidden;
    background: #fff;
    margin: 50rpx 75rpx;
    border-radius: 20rpx;
    padding: 20rpx 20rpx 10rpx;
}
.btn.btn-success{
	background: #5cb85c;
	margin: 40rpx 30rpx;
}
</style>
